//
//  ZMPostDetailBottomToolView.m
//  基本框架
//
//  Created by runone02 on 2018/7/10.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "ZMPostDetailBottomToolView.h"

@implementation ZMPostDetailBottomToolView

- (UIView *)mainView{
    if (!_mainView) {
        self.mainView = [[UIView alloc]init];
        self.mainView.backgroundColor = [ZMColor colorWithHexString:@"#ffffff" alpha:0.5];
        [self addSubview:self.mainView];
        
        [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.mas_equalTo(0);
            
        }];
        [self.mainView.superview layoutIfNeeded];
    }
    return _mainView;
}


- (UIButton *)collectButton{
    if (!_collectButton) {
        _collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _collectButton.adjustsImageWhenHighlighted = NO;
        [_collectButton setImage:IMAGE(@"postDetail_collect_default~iphone") forState:UIControlStateNormal];
        
        [_collectButton setImage:IMAGE(@"postDetail_collect~iphone") forState:UIControlStateSelected];
        [self.mainView addSubview:_collectButton];
        
        [_collectButton addTarget:self action:@selector(clickCollectButton:) forControlEvents:UIControlEventTouchUpInside];
        
        [_collectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.commentButton. mas_left).with.offset(-50);
            make.width.mas_equalTo(40);
            make.height.mas_equalTo(40);
            make.centerY.mas_equalTo(self.mainView);
        }];
        [_collectButton.superview layoutIfNeeded];
        
    }
    return _collectButton;
}


- (UIButton *)praiseButton{
    if (!_praiseButton) {
        _praiseButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _praiseButton.adjustsImageWhenHighlighted = NO;
        [_praiseButton setImage:IMAGE(@"postDetail_support_default~iphone") forState:UIControlStateNormal];
        
        [_praiseButton setImage:IMAGE(@"postDetail_support~iphone") forState:UIControlStateSelected];
        [_praiseButton setBackgroundImage:IMAGE(@"postDetail_support_default_bg~iphone") forState:UIControlStateNormal];
        
        [_praiseButton setBackgroundImage:[YYImage imageWithColor:[UIColor clearColor]] forState:UIControlStateSelected];
        [_praiseButton setBackgroundImage:IMAGE(@"postDetail_support_default_bg~iphone") forState:UIControlStateNormal];
        
        [self.mainView addSubview:_praiseButton];
        [_praiseButton addTarget:self action:@selector(clickPraiseButton:) forControlEvents:UIControlEventTouchUpInside];
        
        [_praiseButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(self.praiseButton.imageView.image.size);
            make.centerY.mas_equalTo(self.mainView);
            make.left.mas_equalTo(self.commentButton.mas_right).with.offset(30);
        }];
    }
    return _praiseButton;
}



- (UIButton *)commentButton{
    if (!_commentButton) {
        _commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _commentButton.adjustsImageWhenHighlighted = NO;
        _commentButton.titleLabel.font = TITLE_FONT(30);
        _commentButton.layer.masksToBounds = YES;
        _commentButton.layer.cornerRadius = 20;
        _commentButton.backgroundColor = [ZMColor appSupportColor];
        
        [_commentButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_commentButton addTarget:self action:@selector(commentButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.mainView addSubview:_commentButton];
        
        [_commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(130);
            make.height.mas_equalTo(40);
            make.centerY.centerX.mas_equalTo(self.mainView);
        }];
    }
    return _commentButton;
}


/** 评论*/
- (void) commentButtonClick:(UIButton *)btn{
    NSLog(@"评论评论");
}

- (UILabel *)praiseCountLabel{
    if ( !_praiseCountLabel) {
        _praiseCountLabel = [[UILabel alloc]init];
        _praiseCountLabel.textAlignment = NSTextAlignmentCenter;
        _praiseCountLabel.layer.cornerRadius = 6;
        _praiseCountLabel.layer.masksToBounds = YES;
        _praiseCountLabel.font = TITLE_FONT(28);
        _praiseCountLabel.backgroundColor = [ZMColor colorWithHexString:@"#666666"];
        _praiseCountLabel.textColor = [UIColor whiteColor];
        
        [self.praiseButton addSubview:_praiseCountLabel];
        [_praiseCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.praiseButton.mas_right).with.offset(-10);
            make.height.mas_equalTo(15);
            make.top.mas_equalTo(2);
        }];
    }
    return _praiseCountLabel;
}


- (void)setCount:(NSString *)count{
    if (count.length) {
        self.praiseCountLabel.text = count;
        [self.praiseCountLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo([NSString getTitleWidth:count withFontSize:11]+ 10);
        }];
    }
}


- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}


/**
 收藏

 @param btn 按钮
 */
- (void)clickCollectButton:(UIButton *)btn{
    btn.selected = !btn.selected;
    if (self.clickCollectBlock) {
        self.clickCollectBlock(btn.selected);
        NSLog(@"收藏点击");
    }
}


/**
 点赞

 @param btn 按钮
 */
- (void) clickPraiseButton:(UIButton *)btn{
    btn.selected = !btn.selected;
    if (self.clickPraiseBlock) {
        self.clickPraiseBlock(btn.selected);
        NSLog(@"点赞👍");
    }
}

@end
